<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>第 1 页 | YouN 科技温度</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  
  
  
  <meta property="og:type" content="website">
<meta property="og:title" content="YouN 科技温度">
<meta property="og:url" content="http://this4u.cn/index.html">
<meta property="og:site_name" content="YouN 科技温度">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Timmy">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="YouN 科技温度" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">

  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Oswald%3A300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  
<link rel="stylesheet" href="/css/style.css">


  
<script src="/js/jquery-3.1.1.min.js"></script>


  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/fashion.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >

<meta name="generator" content="Hexo 6.3.0"></head>



  <body>


  


<header id="allheader" class="site-header" role="banner" 
   >
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" rel="home" >
                <img style="margin-bottom: 2px;"  width="126px" height="60px" alt="Hike News" src=" /css/images/youu.jpg">
              </a>
            
          </h1>
          
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>

            <div class="clearfix sf-menu">
              <ul id="main-nav" class="menu sf-js-enabled sf-arrows"  style="touch-action: pan-y;">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="/"> <a class="" href="/">首页</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="archives"> <a class="" href="/archives">归档</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="categories"> <a class="" href="/categories">分类</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="tags"> <a class="" href="/tags">标签</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="about"> <a class="" href="/about">关于</a> </li>
                    
              </ul>
            </div>
          </nav>

      </div>
  </div>
</header>


  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main">
  
    <article id="post-debug-mysql-with-clion"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2022/04/22/debug-mysql-with-clion/">使用Clion调试MySQL Server源码</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2022/04/22/debug-mysql-with-clion/" class="article-date">
	  <time datetime="2022-04-22T06:34:04.000Z" itemprop="datePublished">四月 22, 2022</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><blockquote>
<p>Mac OS (m1) </p>
<p>Clion</p>
<p>MySQL 8.0 源码 <a target="_blank" rel="noopener" href="https://github.com/mysql/mysql-server">https://github.com/mysql/mysql-server</a></p>
<p>MySQL 8.0 boost_1_73_0 依赖，源码安装</p>
</blockquote>
<h3 id="Boost-下载安装"><a href="#Boost-下载安装" class="headerlink" title="Boost 下载安装"></a>Boost 下载安装</h3><p>最新版并不是MySQL需要的，MySQL 8.0 默认需要的是boost_1_73_0，如果版本不符合要求，编译启动过程中会有相应的提示。</p>
<p><a target="_blank" rel="noopener" href="https://www.boost.org/users/history/version_1_73_0.html">https://www.boost.org/users/history/version_1_73_0.html</a></p>
<p><a target="_blank" rel="noopener" href="https://www.boost.org/doc/libs/1_73_0/more/getting_started/unix-variants.html">https://www.boost.org/doc/libs/1_73_0/more/getting_started/unix-variants.html</a></p>
<p>正常来说下载，解压到指定目录即可，这里我们把boost解压到 <code>/usr/local/</code> 目录下 ，追加 BOOST_ROOT 到 PATH 环境变量。</p>
<h3 id="下载-MySQL-Server-源码"><a href="#下载-MySQL-Server-源码" class="headerlink" title="下载 MySQL-Server 源码"></a>下载 MySQL-Server 源码</h3><p><code>git clone git@github.com:mysql/mysql-server.git</code></p>
<h2 id="Clion-配置Debug"><a href="#Clion-配置Debug" class="headerlink" title="Clion 配置Debug"></a>Clion 配置Debug</h2><h3 id="用Clion打开MySQL-Server-源码工程，配置cmake"><a href="#用Clion打开MySQL-Server-源码工程，配置cmake" class="headerlink" title="用Clion打开MySQL Server 源码工程，配置cmake"></a>用Clion打开MySQL Server 源码工程，配置cmake</h3><p><img src="/images/cmake.png" alt="cmake"></p>
<p>Cmake 配置如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">-DWITH_DEBUG=1 </span><br><span class="line">-DWITH_BOOST=/usr/local/boost_1_73_0</span><br></pre></td></tr></table></figure>

<h3 id="运行Cmake"><a href="#运行Cmake" class="headerlink" title="运行Cmake"></a>运行Cmake</h3><p><img src="/images/reload.png" alt="reload"></p>
<h2 id="Debug-MySQL-Server"><a href="#Debug-MySQL-Server" class="headerlink" title="Debug MySQL Server"></a>Debug MySQL Server</h2><h3 id="选择-MySQL-Server-启动入口"><a href="#选择-MySQL-Server-启动入口" class="headerlink" title="选择 MySQL Server 启动入口"></a>选择 MySQL Server 启动入口</h3><p><img src="/images/mysqld.png" alt="mysqld"></p>
<p>需要配置MySQL Server的相关目录，更多配置项 <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html">https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html</a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">--basedir=/Users/timmy/mysql </span><br><span class="line">--datadir=/Users/timmy/mysql/data</span><br></pre></td></tr></table></figure>

<p>然后点击Debug即可，如果我们本地安装有mysql client，这时候就可以通过客户端免密登录了。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root --skip-password</span><br></pre></td></tr></table></figure>



<h3 id="选择配置-MySQL-指令，在clion中连接启动的mysqld-（本地有mysql客户端可以不用）"><a href="#选择配置-MySQL-指令，在clion中连接启动的mysqld-（本地有mysql客户端可以不用）" class="headerlink" title="选择配置 MySQL 指令，在clion中连接启动的mysqld （本地有mysql客户端可以不用）"></a>选择配置 MySQL 指令，在clion中连接启动的mysqld （本地有mysql客户端可以不用）</h3><p><img src="/images/mysql.png" alt="mysql"></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql-server-debug-clion/" rel="tag">mysql-server debug clion</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-dev-prepare"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2021/08/12/dev-prepare/">通用开发环境搭建</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2021/08/12/dev-prepare/" class="article-date">
	  <time datetime="2021-08-12T07:32:34.000Z" itemprop="datePublished">八月 12, 2021</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p>以下文件安装默认目录为~&#x2F;dev  </p>
<p>~&#x2F;dev 后续路径为解压包后的完整路径</p>
</blockquote>
<h2 id="Java-开发环境搭建"><a href="#Java-开发环境搭建" class="headerlink" title="Java 开发环境搭建"></a>Java 开发环境搭建</h2><p><a target="_blank" rel="noopener" href="https://www.oracle.com/java/technologies/javase-downloads.html">Java SE Downloads</a></p>
<blockquote>
<p>一般选择压缩包(Compressed Archive)安装, 这样可以定制化安装到指定目录。</p>
<p>如果是ARM架构，建议使用<a target="_blank" rel="noopener" href="https://www.azul.com/downloads/?package=jdk#download-openjdk">Zulu -CA-macos-aarch64</a> ARM 64-bit</p>
</blockquote>
<h3 id="环境变量"><a href="#环境变量" class="headerlink" title="环境变量"></a>环境变量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">JAVA_HOME=~/dev/zulu8.56.0.23-ca-jdk8.0.302-macosx_aarch64/zulu-8.jdk/Contents/Home</span><br><span class="line">PATH=$PATH:$JAVA_HOME/bin</span><br><span class="line">CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar</span><br></pre></td></tr></table></figure>

<h2 id="MAVEN-安装及配置"><a href="#MAVEN-安装及配置" class="headerlink" title="MAVEN 安装及配置"></a>MAVEN 安装及配置</h2><blockquote>
<p>下载tar.gz 解压即可，最好不要修改settings.xml里面的localRepository，因为idea内置maven，默认的目录为.m2，因此如果要修改settings.xml，需要一并修改。</p>
</blockquote>
<h3 id="环境变量-1"><a href="#环境变量-1" class="headerlink" title="环境变量"></a>环境变量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">MAVEN_HOME=~/dev/apache-maven-3.8.1</span><br><span class="line">PATH=$PATH:$MAVEN_HOME/bin</span><br></pre></td></tr></table></figure>



<h2 id="MySQL-Client-安装"><a href="#MySQL-Client-安装" class="headerlink" title="MySQL Client 安装"></a>MySQL Client 安装</h2><blockquote>
<p>MySQL Server 在mac机器上一般使用docker(也有arm版了)安装，以便切换不同的mysql版本。</p>
<p>MySQL Client 则可以使用mysql的安装包里面工具。如果是ARM架构，可选择<a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/mysql/">macos11-arm64</a>  arm64.tar.gz</p>
</blockquote>
<h3 id="环境变量-2"><a href="#环境变量-2" class="headerlink" title="环境变量"></a>环境变量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">PATH=$PATH:~/dev/mysql-8.0.26-macos11-arm64/bin</span><br></pre></td></tr></table></figure>



<h2 id="Github-GitLab-SSH-keys-配置"><a href="#Github-GitLab-SSH-keys-配置" class="headerlink" title="Github  GitLab SSH keys 配置"></a>Github  GitLab SSH keys 配置</h2><blockquote>
<p>ed25519加密解密很快,生成时间短而且安全性更高,rsa则加密解密稍慢,生成时间长,安全性没有ed25519高,只是rsa基本都是默认,所以用的人更多,但是建议转换为ed25519,网站软件现在基本都支持了.</p>
</blockquote>
<h3 id="Github-ed25519"><a href="#Github-ed25519" class="headerlink" title="Github (ed25519)"></a>Github (ed25519)</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t ed25519 -C &quot;your_email@example.com&quot;</span><br></pre></td></tr></table></figure>

<h3 id="GitLab-rsa"><a href="#GitLab-rsa" class="headerlink" title="GitLab (rsa)"></a>GitLab (rsa)</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C &quot;your_email@example.com&quot;</span><br></pre></td></tr></table></figure>

<h3 id="配置ssh-config"><a href="#配置ssh-config" class="headerlink" title="配置ssh config"></a>配置ssh config</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">将上面生成的id_rsa 及 id_rsa.pub 分别移动到github和gitlab目录</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cat</span> ~/.ssh/config</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">gitlab</span></span><br><span class="line">Host gitlab.*.com</span><br><span class="line">    HostName gitlab.company.com</span><br><span class="line">    PreferredAuthentications publickey</span><br><span class="line">    IdentityFile ~/.ssh/gitlab/id_rsa</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">github</span></span><br><span class="line">Host github.com</span><br><span class="line">    HostName github.com</span><br><span class="line">    AddKeysToAgent yes</span><br><span class="line">    UseKeychain yes</span><br><span class="line">    PreferredAuthentications publickey</span><br><span class="line">    IdentityFile ~/.ssh/github/id_ed25519</span><br></pre></td></tr></table></figure>



<h3 id="验证SSH是否配置成功"><a href="#验证SSH是否配置成功" class="headerlink" title="验证SSH是否配置成功"></a>验证SSH是否配置成功</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ssh -vT git@github.com</span><br><span class="line">ssh -vT git@gitlab.company.com</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java-maven-docker-mysql-gitlab-github/" rel="tag">java maven docker mysql gitlab github</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-zsh"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2021/08/11/zsh/">安装zsh及主题(Mac)</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2021/08/11/zsh/" class="article-date">
	  <time datetime="2021-08-11T05:55:06.000Z" itemprop="datePublished">八月 11, 2021</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Install-Homebrew"><a href="#Install-Homebrew" class="headerlink" title="Install Homebrew"></a>Install Homebrew</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;</span><br></pre></td></tr></table></figure>



<h2 id="Install-Oh-My-Zsh"><a href="#Install-Oh-My-Zsh" class="headerlink" title="Install Oh My Zsh"></a>Install Oh My Zsh</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sh -c &quot;$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)&quot;</span><br></pre></td></tr></table></figure>



<h2 id="Install-Powerline-fonts"><a href="#Install-Powerline-fonts" class="headerlink" title="Install Powerline fonts"></a>Install Powerline fonts</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">clone</span></span></span><br><span class="line">git clone https://github.com/powerline/fonts.git --depth=1</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">install</span></span><br><span class="line">cd fonts</span><br><span class="line">./install.sh</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">clean-up a bit</span></span><br><span class="line">cd ..</span><br><span class="line">rm -rf fonts</span><br></pre></td></tr></table></figure>

<h2 id="配置-zsh-支持图标"><a href="#配置-zsh-支持图标" class="headerlink" title="配置 zsh 支持图标"></a>配置 zsh 支持图标</h2><p><img src="https://img-blog.csdnimg.cn/img_convert/353b1531f225d06e3719ba6d10a14a3e.png" alt="配色设置"><br><img src="https://img-blog.csdnimg.cn/img_convert/141e68d3b4b5bb5b5865317bab23c9fc.png" alt="箭头图标等支持Powerline字体"></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/zsh-oh-my-zsh/" rel="tag">zsh oh-my-zsh</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-mysql-architecture"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2021/06/30/mysql-architecture/">MySQL-architecture</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2021/06/30/mysql-architecture/" class="article-date">
	  <time datetime="2021-06-30T02:25:18.000Z" itemprop="datePublished">六月 30, 2021</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p><strong>MySQL</strong> is Relational Database Management system which is free Open Source Software Under  GNU License. It  is also supported by Oracle Company .It is fast , scalable, easy to use database management System. MySQL support many operation system like Windows, Linux, MacOS etc.</p>
<p>MySQL is Structured Query Language which is used to manipulate, manage  and retrieve data with the help of various Queries.</p>
<p>MySQL is developed and supported by  MySQL AB which is a Swedish  Company and written in C and C++ programming language. It was developed by Michael Widenius and David Hughes .It is often  used to say that MySQL is named after the name of daughter of the co-founder  MIchael  Widenius whose name is ‘My’.</p>
<p><strong>Architecture of MySQL:</strong></p>
<p>Architecture of MySQL describes the relation among the different components of MySQL  System.  MySQL follow Client-Server Architecture. It is designed so that end user that is Clients can access the resources from Computer that is server using various networking services. The Architecture of MySQL contain following major layer’s :</p>
<ul>
<li>Client</li>
<li>Server</li>
<li>Storage Layer</li>
</ul>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/20210211183907/MySQLArchi.png" alt="architecture"></p>
<p><strong>Client Layer:</strong><br>This layer is the topmost layer in the above diagram. The Client give request instructions to the Serve with the help of Client Layer .The Client make request through  Command Prompt or through GUI  screen by using valid MySQL commands and expressions .If the Expressions and commands are valid then the output is obtained on the screen.  Some important services of client layer are :</p>
<ul>
<li>Connection Handling.</li>
<li>Authentication.</li>
<li>Security.</li>
</ul>
<p><strong>Connection Handling :</strong><br>When a client send request to the server and server will accept the request and the client is connected .. When Client is connected to the server at that time , a client get it’s own thread for it’s connection. With the help of this thread all the queries from client side is executed.</p>
<p><strong>Authentication :</strong><br>Authentication is performed on the server side when client is connected to the MySQL server. Authentication is done with the help of username and password.</p>
<p><strong>Security :</strong><br>After authentication when  the client gets connected successfully to MySQL server, the server will check  that a particular client has the privileges to issue in certain queries against MySQL server.</p>
<p><strong>Server Layer:</strong><br>The second layer of MySQL architecture is responsible for all logical functionalities of relational database management system of MySQL. This Layer of MySQL System is also known as <em><strong>“Brain of MySQL Architecture”</strong></em>. When the Client give request instructions to the Server and the server gives the output as soon as the the instruction is matched.  The various sub components of MySQL server are:</p>
<ul>
<li><strong>Thread Handling –</strong><br>When a client send request to the server and server will accept the request and the client is connected .. When Client is connected to the server at that time , a client get it’s own thread for it’s connection. This thread is provided by  thread handling  of Server Layer. Also the queries of  client side  which is executed by the thread  is also handled by Thread Handling module.</li>
<li><strong>Parser –</strong><br>A Parser is a type of Software Component that  built a data structure(parse tree)  of  given input . Before parsing lexical  analysis is done i.e. input is broken into number of tokens . After the  data is available in the smaller elements parser perform Syntax Analysis , Semantics  Analysis after that parse tree is generated as output.</li>
<li><strong>Optimizer –</strong><br>As soon as the parsing is done ,  various types of optimization techniques are applied at Optimizer Block. These techniques may include rewriting the query, order of scanning of tables and choosing the right indexes to use etc.</li>
<li><strong>Query Cache –</strong><br>Query Cache stores the complete result set for inputted query statement. Eve before Parsing , MySQL Server consult query cache . When client write a query , if the query written by client is identical in the cache then the server simply skip the parsing, optimization and even execution, it just simply display the output from the cache.</li>
<li><strong>Buffer and Cache –</strong><br>Cache and will buffer store the previous query or problem asked by user. When User write a query then it firstly goes to Query Cache then query cache will check that the same query or problem is available in the cache. If the same query is available then it will provide output without interfering Parser, Optimizer.</li>
<li><strong>Table Metadata Cache –</strong><br>The metadata cache is a reserved area of memory used for tracking information on databases, indexes, or objects. The greater the number of open databases, indexes, or objects, the larger the metadata cache size.</li>
<li><strong>Key Cache –</strong><br>A  key cache  is an index entry that uniquely identifies an object in a cache. By default, edge servers cache content based on the entire resource path and a query string.</li>
</ul>
<p><strong>Storage Layer:</strong><br>This Storage Engine Layer of MySQL Architecture make it’s unique and most preferable for developer’s . Due to this Layer MySQL layer is counted as the mostly used RDBMS and is widely used. In MySQL server , for different situations and requirement’s different types of storage engines are used which are InnoDB ,MyISAM , NDB ,Memory etc. These storage engines are used as pluggable  storage enginer where tables created by user are plugged with them.</p>
<p><strong>Features of MySQL:</strong></p>
<ol>
<li>MySQL language is easy to use as compared to other programming language like C,C++, Java etc. By learning with some basic command we can work , create and interact with Database.</li>
<li>MySQL consist of  Data Security layer  which protect the data from violator. Also, passwords are encrypted in MySQL.</li>
<li>MySQL follow Client-Server Architecture where  Client request Commands and instructions and Server will produce output  as soon as the instruction is matched.</li>
<li>MySQL is free to use under Community version of it. So we can download it from MySQL website and work on it freely.</li>
<li>MySQL use multithreading which makes it Scalable. It can handle any amount of data .The default file size limit is 4 GB, but we can increase it according to our need.</li>
<li>MySQL is considered as one of the fast database. It’s fastness is determined on the basis of large number of benchmark tests.</li>
<li>MySQL is very flexible because  it supports large number of embedded systems.</li>
<li>MySQL is compatible to run on various operating system such as Windows, MacOS , Linux etc.</li>
<li>MySQL allow transactions to be rolled back, commit and cash recovery.</li>
<li>It has low memory leakage problem which increase its memory efficiency.</li>
<li>MySQL version 8.0 provide dual password support , one is a current password and another is secondary password. With the help of this we can create new password.</li>
<li>MySQL provide feature of Partitioning  which improve performance of large databases.</li>
</ol>
<p>Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the <a target="_blank" rel="noopener" href="https://practice.geeksforgeeks.org/courses/SDE-theory?vC=1"><strong>CS Theory Course</strong></a> at a student-friendly price and become industry ready.</p>
<p><strong>Reference</strong></p>
<p><a target="_blank" rel="noopener" href="https://www.geeksforgeeks.org/architecture-of-MySQL/">architecture-of-MySQL</a></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MySQL-architecture/" rel="tag">MySQL architecture</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-docker-net"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2021/01/12/docker-net/">docker_net</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2021/01/12/docker-net/" class="article-date">
	  <time datetime="2021-01-12T02:20:46.000Z" itemprop="datePublished">一月 12, 2021</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Docker-网络问题汇总"><a href="#Docker-网络问题汇总" class="headerlink" title="Docker 网络问题汇总"></a>Docker 网络问题汇总</h2><p>Docker’s networking subsystem is pluggable, using drivers. Several drivers exist by default, and provide core networking functionality:</p>
<ul>
<li><code>bridge</code>: The default network driver. If you don’t specify a driver, this is the type of network you are creating. <strong>Bridge networks are usually used when your applications run in standalone containers that need to communicate.</strong> See <a target="_blank" rel="noopener" href="https://docs.docker.com/network/bridge/">bridge networks</a>.</li>
<li><code>host</code>: For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly. See <a target="_blank" rel="noopener" href="https://docs.docker.com/network/host/">use the host network</a>.</li>
<li><code>overlay</code>: Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons. This strategy removes the need to do OS-level routing between these containers. See <a target="_blank" rel="noopener" href="https://docs.docker.com/network/overlay/">overlay networks</a>.</li>
<li><code>macvlan</code>: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the <code>macvlan</code> driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to the physical network, rather than routed through the Docker host’s network stack. See <a target="_blank" rel="noopener" href="https://docs.docker.com/network/macvlan/">Macvlan networks</a>.</li>
<li><code>none</code>: For this container, disable all networking. Usually used in conjunction with a custom network driver. <code>none</code> is not available for swarm services. See <a target="_blank" rel="noopener" href="https://docs.docker.com/network/none/">disable container networking</a>.</li>
<li><a target="_blank" rel="noopener" href="https://docs.docker.com/engine/extend/plugins_services/">Network plugins</a>: You can install and use third-party network plugins with Docker. These plugins are available from <a target="_blank" rel="noopener" href="https://hub.docker.com/search?category=network&q=&type=plugin">Docker Hub</a> or from third-party vendors. See the vendor’s documentation for installing and using a given network plugin.</li>
</ul>
<h2 id="常用类型"><a href="#常用类型" class="headerlink" title="常用类型"></a>常用类型</h2><ul>
<li>bridge 很容易打通各个容器之间的通信</li>
<li>host 复用宿主机网络</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建my-net私网（各容器通过my-net这个路由器通信，容器不能直接打通宿主机）</span></span><br><span class="line">docker network create my-net</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">删除my-net私网</span></span><br><span class="line">docker network rm my-net</span><br></pre></td></tr></table></figure>




      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker-net/" rel="tag">docker net</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-jdb"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/08/26/jdb/">jdb</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/08/26/jdb/" class="article-date">
	  <time datetime="2020-08-26T10:55:44.000Z" itemprop="datePublished">八月 26, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p><a target="_blank" rel="noopener" href="https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/introclientissues005.html">jdb官方</a></p>
<h2 id="操作实例"><a href="#操作实例" class="headerlink" title="操作实例"></a>操作实例</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.concurrent.TimeUnit;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Hello</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> InterruptedException &#123;</span><br><span class="line">        <span class="type">int</span> <span class="variable">wait</span> <span class="operator">=</span> <span class="number">20</span>;</span><br><span class="line">        <span class="keyword">if</span> (args.length &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            wait = Integer.parseInt(args[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> (i++ &lt; wait) &#123;</span><br><span class="line">            System.out.println(i);</span><br><span class="line">            TimeUnit.SECONDS.sleep(<span class="number">10</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(<span class="string">&quot;exit...&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// com.sun.tools.example.debug.expr.ParseException: Name unknown: wait</span><br><span class="line">// wait = null</span><br><span class="line">javac -g Hello.java #没有-g参数，jdb print 变量 如上错误</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="执行"><a href="#执行" class="headerlink" title="执行"></a>执行</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">win 系统指令有差异</span></span><br><span class="line">java -Xdebug -Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=y Hello</span><br></pre></td></tr></table></figure>



<h2 id="IDEA-Remote-Debug"><a href="#IDEA-Remote-Debug" class="headerlink" title="IDEA Remote Debug"></a>IDEA Remote Debug</h2><p><img src="/images/image-20210816195342742.png" alt="image-20210816195342742"></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/debug-jdb/" rel="tag">debug jdb</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-ClassLoader"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/07/06/ClassLoader/">ClassLoader</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/07/06/ClassLoader/" class="article-date">
	  <time datetime="2020-07-06T02:49:03.000Z" itemprop="datePublished">七月 6, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p><img src="https://user-gold-cdn.xitu.io/2018/12/1/167678affe2ff88d?imageslim"></p>
<blockquote>
<p>不同的 ClassLoader 之间也会有合作，它们之间的合作是通过 parent 属性和双亲委派机制来完成的。parent 具有更高的加载优先级。除此之外，parent 还表达了一种共享关系，当多个子 ClassLoader 共享同一个 parent 时，那么这个 parent 里面包含的类可以认为是所有子 ClassLoader 共享的。这也是为什么 BootstrapClassLoader 被所有的类加载器视为祖先加载器，JVM 核心类库自然应该被共享。</p>
</blockquote>
<h2 id="双亲委派"><a href="#双亲委派" class="headerlink" title="双亲委派"></a>双亲委派</h2><blockquote>
<p>双亲委派规则可能会变成三亲委派，四亲委派，取决于你使用的父加载器是谁，它会一直递归委派到根加载器。</p>
</blockquote>
<h2 id="自定义加载器"><a href="#自定义加载器" class="headerlink" title="自定义加载器"></a>自定义加载器</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">ClassLoader</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 加载入口，定义了双亲委派规则</span></span><br><span class="line">  Class <span class="title function_">loadClass</span><span class="params">(String name)</span> &#123;</span><br><span class="line">    <span class="comment">// 是否已经加载了</span></span><br><span class="line">    <span class="type">Class</span> <span class="variable">t</span> <span class="operator">=</span> <span class="built_in">this</span>.findFromLoaded(name);</span><br><span class="line">    <span class="keyword">if</span>(t == <span class="literal">null</span>) &#123;</span><br><span class="line">      <span class="comment">// 交给双亲</span></span><br><span class="line">      t = <span class="built_in">this</span>.parent.loadClass(name)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(t == <span class="literal">null</span>) &#123;</span><br><span class="line">      <span class="comment">// 双亲都不行，只能靠自己了</span></span><br><span class="line">      t = <span class="built_in">this</span>.findClass(name);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> t;</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// 交给子类自己去实现</span></span><br><span class="line">  Class <span class="title function_">findClass</span><span class="params">(String name)</span> &#123;</span><br><span class="line">    <span class="keyword">throw</span> ClassNotFoundException();</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// 组装Class对象</span></span><br><span class="line">  Class <span class="title function_">defineClass</span><span class="params">(<span class="type">byte</span>[] code, String name)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> buildClassFromCode(code, name);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">CustomClassLoader</span> <span class="keyword">extends</span> <span class="title class_">ClassLoader</span> &#123;</span><br><span class="line"></span><br><span class="line">  Class <span class="title function_">findClass</span><span class="params">(String name)</span> &#123;</span><br><span class="line">    <span class="comment">// 寻找字节码</span></span><br><span class="line">    <span class="type">byte</span>[] code = findCodeFromSomewhere(name);</span><br><span class="line">    <span class="comment">// 组装Class对象</span></span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">this</span>.defineClass(code, name);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>自定义类加载器不易破坏双亲委派规则，不要轻易覆盖 loadClass 方法。否则可能会导致自定义加载器无法加载内置的核心类库。在使用自定义加载器时，要明确好它的父加载器是谁，将父加载器通过子类的构造器传入。如果父类加载器是 null，那就表示父加载器是「根加载器」。</p>
</blockquote>
<h2 id="Class-forName-vs-ClassLoader-loadClass"><a href="#Class-forName-vs-ClassLoader-loadClass" class="headerlink" title="Class.forName vs ClassLoader.loadClass"></a>Class.forName vs ClassLoader.loadClass</h2><blockquote>
<p>这两个方法都可以用来加载目标类，它们之间有一个小小的区别，那就是 Class.forName() 方法可以获取原生类型的 Class，而 ClassLoader.loadClass() 则会报错。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Class&lt;?&gt; x = Class.forName(<span class="string">&quot;[I&quot;</span>);</span><br><span class="line">System.out.println(x);</span><br><span class="line"></span><br><span class="line">x = ClassLoader.getSystemClassLoader().loadClass(<span class="string">&quot;[I&quot;</span>);</span><br><span class="line">System.out.println(x);</span><br><span class="line"></span><br><span class="line">---------------------</span><br><span class="line">class [I</span><br><span class="line"></span><br><span class="line">Exception in thread <span class="string">&quot;main&quot;</span> java.lang.ClassNotFoundException: [I</span><br><span class="line">...</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="钻石依赖"><a href="#钻石依赖" class="headerlink" title="钻石依赖"></a>钻石依赖</h2><p>项目管理上有一个著名的概念叫着「钻石依赖」，是指软件依赖导致同一个软件包的两个版本需要共存而不能冲突。</p>
<p><img src="https://user-gold-cdn.xitu.io/2018/12/1/167678b005f268c5?imageslim"></p>
<p>我们平时使用的 maven 是这样解决钻石依赖的，它会从多个冲突的版本中选择一个来使用，如果不同的版本之间兼容性很糟糕，那么程序将无法正常编译运行。Maven 这种形式叫「扁平化」依赖管理。</p>
<p>使用 ClassLoader 可以解决钻石依赖问题。不同版本的软件包使用不同的 ClassLoader 来加载，<strong>位于不同 ClassLoader 中名称一样的类实际上是不同的类</strong>。下面让我们使用 URLClassLoader 来尝试一个简单的例子，它默认的父加载器是 AppClassLoader。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cat</span> ~/source/jcl/v1/Dep.java</span></span><br><span class="line">public class Dep &#123;</span><br><span class="line">	public void print() &#123;</span><br><span class="line">		System.out.println(&quot;v1&quot;);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cat</span> ~/source/jcl/v2/Dep.java</span></span><br><span class="line">public class Dep &#123;</span><br><span class="line"> public void print() &#123;</span><br><span class="line">  System.out.println(&quot;v1&quot;);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cat</span> ~/source/jcl/Test.java</span></span><br><span class="line">public class Test &#123;</span><br><span class="line">	public static void main(String[] args) throws Exception &#123;</span><br><span class="line">		String v1dir = &quot;file:///Users/qianwp/source/jcl/v1/&quot;;</span><br><span class="line">		String v2dir = &quot;file:///Users/qianwp/source/jcl/v2/&quot;;</span><br><span class="line">		URLClassLoader v1 = new URLClassLoader(new URL[]&#123;new URL(v1dir)&#125;);</span><br><span class="line">		URLClassLoader v2 = new URLClassLoader(new URL[]&#123;new URL(v2dir)&#125;);</span><br><span class="line">		</span><br><span class="line">    Class&lt;?&gt; depv1Class = v1.loadClass(&quot;Dep&quot;);</span><br><span class="line">		Object depv1 = depv1Class.getConstructor().newInstance();</span><br><span class="line">		depv1Class.getMethod(&quot;print&quot;).invoke(depv1);</span><br><span class="line"></span><br><span class="line">		Class&lt;?&gt; depv2Class = v2.loadClass(&quot;Dep&quot;);</span><br><span class="line">		Object depv2 = depv2Class.getConstructor().newInstance();</span><br><span class="line">		depv2Class.getMethod(&quot;print&quot;).invoke(depv2);</span><br><span class="line">	 </span><br><span class="line">  System.out.println(depv1Class.equals(depv2Class));</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cd</span> ~/source/jcl/v1</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">javac Dep.java</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cd</span> ~/source/jcl/v2</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">javac Dep.java</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cd</span> ~/source/jcl</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">javac Test.java</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">java Test</span></span><br><span class="line">v1</span><br><span class="line">v2</span><br><span class="line">false</span><br></pre></td></tr></table></figure>

<p>在这个例子中如果两个 URLClassLoader 指向的路径是一样的，下面这个表达式还是 false，因为即使是同样的字节码用不同的 ClassLoader 加载出来的类都不能算同一个类</p>
<p>我们还可以让两个不同版本的 Dep 类实现同一个接口，这样可以避免使用反射的方式来调用 Dep 类里面的方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Class&lt;?&gt; depv1Class = v1.loadClass(<span class="string">&quot;Dep&quot;</span>);</span><br><span class="line"><span class="type">IPrint</span> <span class="variable">depv1</span> <span class="operator">=</span> (IPrint)depv1Class.getConstructor().newInstance();</span><br><span class="line">depv1.print()</span><br></pre></td></tr></table></figure>

<p>ClassLoader 固然可以解决依赖冲突问题，不过它也限制了不同软件包的操作界面必须使用反射或接口的方式进行动态调用。Maven 没有这种限制，它依赖于虚拟机的默认懒惰加载策略，运行过程中如果没有显示使用定制的 ClassLoader，那么从头到尾都是在使用 AppClassLoader，而不同版本的同名类必须使用不同的 ClassLoader 加载，所以 Maven 不能完美解决钻石依赖。 如果你想知道有没有开源的包管理工具可以解决钻石依赖的，我推荐你了解一下 sofa-ark，它是蚂蚁金服开源的轻量级类隔离框架。</p>
<h2 id="Thread-contextClassLoader"><a href="#Thread-contextClassLoader" class="headerlink" title="Thread.contextClassLoader"></a>Thread.contextClassLoader</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Thread</span> &#123;</span><br><span class="line">  ...</span><br><span class="line">  <span class="keyword">private</span> ClassLoader contextClassLoader;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">public</span> ClassLoader <span class="title function_">getContextClassLoader</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> contextClassLoader;</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setContextClassLoader</span><span class="params">(ClassLoader cl)</span> &#123;</span><br><span class="line">    <span class="built_in">this</span>.contextClassLoader = cl;</span><br><span class="line">  &#125;</span><br><span class="line">  ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>contextClassLoader「线程上下文类加载器」，这究竟是什么东西？</p>
<p>首先 contextClassLoader 是那种需要显示使用的类加载器，如果你没有显示使用它，也就永远不会在任何地方用到它。你可以使用下面这种方式来显示使用它</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Thread.currentThread().getContextClassLoader().loadClass(name);</span><br></pre></td></tr></table></figure>

<p>这意味着如果你使用 forName(string name) 方法加载目标类，它不会自动使用 contextClassLoader。那些因为代码上的依赖关系而懒惰加载的类也不会自动使用 contextClassLoader来加载。</p>
<p>其次线程的 contextClassLoader 默认是从父线程那里继承过来的，所谓父线程就是创建了当前线程的线程。程序启动时的 main 线程的 contextClassLoader 就是 AppClassLoader。这意味着如果没有人工去设置，那么所有的线程的 contextClassLoader 都是 AppClassLoader。</p>
<p>那这个 contextClassLoader 究竟是做什么用的？我们要使用前面提到了类加载器分工与合作的原理来解释它的用途。</p>
<p>它可以做到跨线程共享类，只要它们共享同一个 contextClassLoader。父子线程之间会自动传递 contextClassLoader，所以共享起来将是自动化的。</p>
<p>如果不同的线程使用不同的 contextClassLoader，那么不同的线程使用的类就可以隔离开来。</p>
<p>如果我们对业务进行划分，不同的业务使用不同的线程池，线程池内部共享同一个 contextClassLoader，线程池之间使用不同的 contextClassLoader，就可以很好的起到隔离保护的作用，避免类版本冲突。</p>
<p>如果我们不去定制 contextClassLoader，那么所有的线程将会默认使用 <strong>AppClassLoader</strong>，所有的类都将会是<strong>共享</strong>的。</p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/jvm-classloader/" rel="tag">jvm classloader</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-mysql-xa"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/06/15/mysql-xa/">mysql-xa</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/06/15/mysql-xa/" class="article-date">
	  <time datetime="2020-06-15T09:31:42.000Z" itemprop="datePublished">六月 15, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>MySQL XA</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">boolean</span> <span class="variable">logXaCommands</span> <span class="operator">=</span> <span class="literal">true</span>;</span><br><span class="line">   <span class="comment">// 获得资源管理器操作接口实例 RM1</span></span><br><span class="line">   <span class="type">Connection</span> <span class="variable">conn1</span> <span class="operator">=</span> DriverManager.getConnection(<span class="string">&quot;jdbc:mysql://localhost:33060/d1&quot;</span>, <span class="string">&quot;root&quot;</span>, <span class="string">&quot;pass&quot;</span>);</span><br><span class="line">   <span class="type">XAConnection</span> <span class="variable">xaConn1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MysqlXAConnection</span>((JdbcConnection)conn1, logXaCommands);</span><br><span class="line">   <span class="type">XAResource</span> <span class="variable">rm1</span> <span class="operator">=</span> xaConn1.getXAResource();</span><br><span class="line"></span><br><span class="line">   <span class="comment">// 获得资源管理器操作接口实例 RM2</span></span><br><span class="line">   <span class="type">Connection</span> <span class="variable">conn2</span> <span class="operator">=</span> DriverManager.getConnection(<span class="string">&quot;jdbc:mysql://localhost:33060/d2&quot;</span>, <span class="string">&quot;root&quot;</span>, <span class="string">&quot;pass&quot;</span>);</span><br><span class="line">   <span class="type">XAConnection</span> <span class="variable">xaConn2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MysqlXAConnection</span>((JdbcConnection)conn2, logXaCommands);</span><br><span class="line">   <span class="type">XAResource</span> <span class="variable">rm2</span> <span class="operator">=</span> xaConn2.getXAResource();</span><br><span class="line">   <span class="comment">// AP请求TM执行一个分布式事务，TM生成全局事务id</span></span><br><span class="line">   <span class="type">byte</span>[] gtrid = <span class="string">&quot;g12345&quot;</span>.getBytes();</span><br><span class="line">   <span class="type">int</span> <span class="variable">formatId</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line">   <span class="keyword">try</span> &#123;</span><br><span class="line">       <span class="comment">// ==============分别执行RM1和RM2上的事务分支====================</span></span><br><span class="line">       <span class="comment">// TM生成rm1上的事务分支id</span></span><br><span class="line">       <span class="type">byte</span>[] bqual1 = <span class="string">&quot;b00001&quot;</span>.getBytes();</span><br><span class="line">       <span class="type">Xid</span> <span class="variable">xid1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MysqlXid</span>(gtrid, bqual1, formatId);</span><br><span class="line">       <span class="comment">// 执行rm1上的事务分支 One of TMNOFLAGS, TMJOIN, or TMRESUME.</span></span><br><span class="line">       rm1.start(xid1, XAResource.TMNOFLAGS);</span><br><span class="line">       <span class="comment">// 业务1：插入user表</span></span><br><span class="line">       <span class="type">PreparedStatement</span> <span class="variable">ps1</span> <span class="operator">=</span> conn1.prepareStatement(<span class="string">&quot;insert into t1 values (10,&#x27;ab&#x27;)&quot;</span>);</span><br><span class="line">       ps1.execute();</span><br><span class="line">       rm1.end(xid1, XAResource.TMSUCCESS);</span><br><span class="line"></span><br><span class="line">       <span class="comment">// TM生成rm2上的事务分支id</span></span><br><span class="line">       <span class="type">byte</span>[] bqual2 = <span class="string">&quot;b00002&quot;</span>.getBytes();</span><br><span class="line">       <span class="type">Xid</span> <span class="variable">xid2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MysqlXid</span>(gtrid, bqual2, formatId);</span><br><span class="line">       <span class="comment">// 执行rm2上的事务分支</span></span><br><span class="line">       rm2.start(xid2, XAResource.TMNOFLAGS);</span><br><span class="line">       <span class="comment">// 业务2：插入user_msg表</span></span><br><span class="line">       <span class="type">PreparedStatement</span> <span class="variable">ps2</span> <span class="operator">=</span> conn2.prepareStatement(<span class="string">&quot;insert into t2 values (20,&#x27;cd&#x27;)&quot;</span>);</span><br><span class="line">       ps2.execute();</span><br><span class="line">       rm2.end(xid2, XAResource.TMSUCCESS);</span><br><span class="line"></span><br><span class="line">       <span class="comment">// ===================两阶段提交================================</span></span><br><span class="line">       <span class="comment">// phase1：询问所有的RM 准备提交事务分支</span></span><br><span class="line">       <span class="type">int</span> <span class="variable">rm1Prepare</span> <span class="operator">=</span> rm1.prepare(xid1);</span><br><span class="line">       <span class="type">int</span> <span class="variable">rm2Prepare</span> <span class="operator">=</span> rm2.prepare(xid2);</span><br><span class="line">       <span class="comment">// phase2：提交所有事务分支</span></span><br><span class="line">       <span class="type">boolean</span> <span class="variable">onePhase</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line">       <span class="comment">//TM判断有2个事务分支，所以不能优化为一阶段提交</span></span><br><span class="line">       <span class="keyword">if</span> (rm1Prepare == XAResource.XA_OK &amp;&amp; rm2Prepare == XAResource.XA_OK) &#123;</span><br><span class="line">           <span class="comment">//所有事务分支都prepare成功，提交所有事务分支</span></span><br><span class="line">           rm1.commit(xid1, onePhase);</span><br><span class="line">           rm2.commit(xid2, onePhase);</span><br><span class="line">       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">           <span class="comment">//如果有事务分支没有成功，则回滚</span></span><br><span class="line">           rm1.rollback(xid1);</span><br><span class="line">           rm1.rollback(xid2);</span><br><span class="line">       &#125;</span><br><span class="line">   &#125; <span class="keyword">catch</span> (XAException e) &#123;</span><br><span class="line">       <span class="comment">// 如果出现异常，也要进行回滚</span></span><br><span class="line">       e.printStackTrace();</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h2 id="事务落在同一个MySQL"><a href="#事务落在同一个MySQL" class="headerlink" title="事务落在同一个MySQL"></a>事务落在同一个MySQL</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">+---------------+------+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| Log_name      | Pos  | Event_type     | Server_id | End_log_pos | Info                                         |</span><br><span class="line">+---------------+------+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| binlog.000001 |    4 | Format_desc    |         1 |         125 | Server ver: 8.0.20, Binlog ver: 4            |</span><br><span class="line">| binlog.000001 |  125 | Previous_gtids |         1 |         156 |                                              |</span><br><span class="line">| binlog.000001 |  156 | Anonymous_Gtid |         1 |         235 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 |  235 | Query          |         1 |         345 | XA START X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1   |</span><br><span class="line">| binlog.000001 |  345 | Table_map      |         1 |         399 | table_id: 94 (d1.t1)                         |</span><br><span class="line">| binlog.000001 |  399 | Write_rows     |         1 |         442 | table_id: 94 flags: STMT_END_F               |</span><br><span class="line">| binlog.000001 |  442 | Query          |         1 |         550 | XA END X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1     |</span><br><span class="line">| binlog.000001 |  550 | XA_prepare     |         1 |         598 | XA PREPARE X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1 |</span><br><span class="line">| binlog.000001 |  598 | Anonymous_Gtid |         1 |         677 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 |  677 | Query          |         1 |         787 | XA START X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1   |</span><br><span class="line">| binlog.000001 |  787 | Table_map      |         1 |         841 | table_id: 96 (d2.t2)                         |</span><br><span class="line">| binlog.000001 |  841 | Write_rows     |         1 |         884 | table_id: 96 flags: STMT_END_F               |</span><br><span class="line">| binlog.000001 |  884 | Query          |         1 |         992 | XA END X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1     |</span><br><span class="line">| binlog.000001 |  992 | XA_prepare     |         1 |        1040 | XA PREPARE X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1 |</span><br><span class="line">| binlog.000001 | 1040 | Anonymous_Gtid |         1 |        1117 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 1117 | Query          |         1 |        1228 | XA COMMIT X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1  |</span><br><span class="line">| binlog.000001 | 1228 | Anonymous_Gtid |         1 |        1305 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 1305 | Query          |         1 |        1416 | XA COMMIT X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1  |</span><br><span class="line">+---------------+------+----------------+-----------+-------------+----------------------------------------------+</span><br></pre></td></tr></table></figure>

<p><img src="https://youuwd.github.io/images/xa.png"></p>
<h2 id="事务落在2个不同MySQL"><a href="#事务落在2个不同MySQL" class="headerlink" title="事务落在2个不同MySQL"></a>事务落在2个不同MySQL</h2><h3 id="MySQL-1"><a href="#MySQL-1" class="headerlink" title="MySQL 1"></a>MySQL 1</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                                         |</span><br><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| binlog.000001 |   4 | Format_desc    |         1 |         125 | Server ver: 8.0.20, Binlog ver: 4            |</span><br><span class="line">| binlog.000001 | 125 | Previous_gtids |         1 |         156 |                                              |</span><br><span class="line">| binlog.000001 | 156 | Anonymous_Gtid |         1 |         235 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 235 | Query          |         1 |         345 | XA START X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1   |</span><br><span class="line">| binlog.000001 | 345 | Table_map      |         1 |         399 | table_id: 101 (d1.t1)                        |</span><br><span class="line">| binlog.000001 | 399 | Write_rows     |         1 |         442 | table_id: 101 flags: STMT_END_F              |</span><br><span class="line">| binlog.000001 | 442 | Query          |         1 |         550 | XA END X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1     |</span><br><span class="line">| binlog.000001 | 550 | XA_prepare     |         1 |         598 | XA PREPARE X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1 |</span><br><span class="line">| binlog.000001 | 598 | Anonymous_Gtid |         1 |         675 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 675 | Query          |         1 |         786 | XA COMMIT X&#x27;673132333435&#x27;,X&#x27;623030303031&#x27;,1  |</span><br><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br></pre></td></tr></table></figure>



<h3 id="MySQL-2"><a href="#MySQL-2" class="headerlink" title="MySQL 2"></a>MySQL 2</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                                         |</span><br><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br><span class="line">| binlog.000001 |   4 | Format_desc    |         1 |         125 | Server ver: 8.0.20, Binlog ver: 4            |</span><br><span class="line">| binlog.000001 | 125 | Previous_gtids |         1 |         156 |                                              |</span><br><span class="line">| binlog.000001 | 156 | Anonymous_Gtid |         1 |         235 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 235 | Query          |         1 |         345 | XA START X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1   |</span><br><span class="line">| binlog.000001 | 345 | Table_map      |         1 |         399 | table_id: 106 (d2.t2)                        |</span><br><span class="line">| binlog.000001 | 399 | Write_rows     |         1 |         442 | table_id: 106 flags: STMT_END_F              |</span><br><span class="line">| binlog.000001 | 442 | Query          |         1 |         550 | XA END X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1     |</span><br><span class="line">| binlog.000001 | 550 | XA_prepare     |         1 |         598 | XA PREPARE X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1 |</span><br><span class="line">| binlog.000001 | 598 | Anonymous_Gtid |         1 |         675 | SET @@SESSION.GTID_NEXT= &#x27;ANONYMOUS&#x27;         |</span><br><span class="line">| binlog.000001 | 675 | Query          |         1 |         786 | XA COMMIT X&#x27;673132333435&#x27;,X&#x27;623030303032&#x27;,1  |</span><br><span class="line">+---------------+-----+----------------+-----------+-------------+----------------------------------------------+</span><br></pre></td></tr></table></figure>





<h4 id=""><a href="#" class="headerlink" title=""></a></h4>
      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql-binlog-xa/" rel="tag">mysql binlog xa</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-binlog-protocol"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/06/02/binlog-protocol/">binlog-protocol</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/06/02/binlog-protocol/" class="article-date">
	  <time datetime="2020-06-02T06:58:21.000Z" itemprop="datePublished">六月 2, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="生成新的binlog"><a href="#生成新的binlog" class="headerlink" title="生成新的binlog"></a>生成新的binlog</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush logs;</span><br></pre></td></tr></table></figure>

<h2 id="清空binlog"><a href="#清空binlog" class="headerlink" title="清空binlog"></a>清空binlog</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reset master;</span><br></pre></td></tr></table></figure>



<h2 id="格式"><a href="#格式" class="headerlink" title="格式"></a>格式</h2><p>Binlog files start with a <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file-header.html">Binlog File Header</a> followed by a series of <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event.html">Binlog Event</a></p>
<p>Header + Event + Event + Event</p>
<p><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file-header.html">Header</a></p>
<p>A binlog file starts with a <code>Binlog File Header</code> <code>[ fe &#39;bin&#39; ]</code></p>
<h2 id="Event"><a href="#Event" class="headerlink" title="Event"></a>Event</h2><p>EventHeader + Event</p>
<h4 id="Binlog-Event-header"><a href="#Binlog-Event-header" class="headerlink" title="Binlog Event header"></a>Binlog Event header</h4><p>The binlog event header starts each event and is either 13 or 19 bytes long, depending on the <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-version.html">binlog version</a>.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">4              timestamp</span><br><span class="line">1              event type</span><br><span class="line">4              server-id</span><br><span class="line">4              event-size</span><br><span class="line">   if binlog-version &gt; 1:</span><br><span class="line">4              log pos</span><br><span class="line">2              flags</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">+---------+---------+---------+------------+-------------+-------+</span><br><span class="line">|timestamp|type code|server_id|event_length|next_position|flags  |</span><br><span class="line">|4 bytes  |1 byte   |4 bytes  |4 bytes     |4 bytes      |2 bytes|</span><br><span class="line">+---------+---------+---------+------------+-------------+-------+</span><br></pre></td></tr></table></figure>



<p><strong>Fields</strong></p>
<ul>
<li><strong>timestamp</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – seconds since unix epoch</li>
<li><strong>event_type</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-1"><em>1</em></a>) – see <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event-type.html">Binlog Event Type</a></li>
<li><strong>server_id</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – server-id of the originating mysql-server. Used to filter out events in circular replication.</li>
<li><strong>event_size</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – size of the event (header, post-header, body)</li>
<li><strong>log_pos</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-4"><em>4</em></a>) – position of the next event</li>
<li><strong>flags</strong> (<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/describing-packets.html#type-2"><em>2</em></a>) – see <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-event-flag.html">Binlog Event Flag</a></li>
</ul>
<p><strong>Table 14.5 Binlog Versions</strong></p>
<table>
<thead>
<tr>
<th>Binlog version</th>
<th>MySQL Version</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>MySQL 3.23 - &lt; 4.0.0</td>
</tr>
<tr>
<td>2</td>
<td>MySQL 4.0.0 - 4.0.1</td>
</tr>
<tr>
<td>3</td>
<td>MySQL 4.0.2 - &lt; 5.0.0</td>
</tr>
<tr>
<td>4</td>
<td>MySQL 5.0.0+</td>
</tr>
</tbody></table>
<p>目前市面上都是V4了，故EventHeader的长度可以默认为19</p>
<p><strong>Binlog::FORMAT_DESCRIPTION_EVENT:</strong></p>
<p>FORMAT_DESCRIPTION_EVENT 是binlog文件的第一个 Event</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://sourcegraph.com/github.com/mysql/mysql-server/-/blob/libbinlogevents/src/binlog_event.cpp#L84:1</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   The method returns the checksum algorithm used to checksum the binary log.</span></span><br><span class="line"><span class="comment">   For MySQL server versions &lt; 5.6, the algorithm is undefined. For the higher</span></span><br><span class="line"><span class="comment">   versions, the type is decoded from the FORMAT_DESCRIPTION_EVENT.</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">   @param buf buffer holding serialized FD event</span></span><br><span class="line"><span class="comment">   @param len netto (possible checksum is stripped off) length of the event buf</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">   @return  the version-safe checksum alg descriptor where zero</span></span><br><span class="line"><span class="comment">            designates no checksum, 255 - the orginator is</span></span><br><span class="line"><span class="comment">            checksum-unaware (effectively no checksum) and the actuall</span></span><br><span class="line"><span class="comment">            [1-254] range alg descriptor.</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function">enum_binlog_checksum_alg <span class="title">Log_event_footer::get_checksum_alg</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *buf,</span></span></span><br><span class="line"><span class="params"><span class="function">                                                            <span class="type">unsigned</span> <span class="type">long</span> len)</span> </span>&#123;</span><br><span class="line">  <span class="built_in">BAPI_ENTER</span>(<span class="string">&quot;Log_event_footer::get_checksum_alg(const char*, unsigned long)&quot;</span>);</span><br><span class="line">  enum_binlog_checksum_alg ret = BINLOG_CHECKSUM_ALG_UNDEF;</span><br><span class="line">  <span class="type">char</span> version[ST_SERVER_VER_LEN];</span><br><span class="line">  <span class="type">unsigned</span> <span class="type">char</span> version_split[<span class="number">3</span>];</span><br><span class="line">  <span class="built_in">BAPI_ASSERT</span>(buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);</span><br><span class="line">  <span class="keyword">if</span> (len &gt; LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET + <span class="number">1</span>) &#123;</span><br><span class="line">    <span class="type">uint8_t</span> common_header_len =</span><br><span class="line">        buf[LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET];</span><br><span class="line">    <span class="keyword">if</span> (len &gt;=</span><br><span class="line">        <span class="built_in">static_cast</span>&lt;<span class="type">unsigned</span> <span class="type">long</span>&gt;(common_header_len + ST_SERVER_VER_OFFSET +</span><br><span class="line">                                   ST_SERVER_VER_LEN)) &#123;</span><br><span class="line">      <span class="built_in">memcpy</span>(version, buf + common_header_len + ST_SERVER_VER_OFFSET,</span><br><span class="line">             ST_SERVER_VER_LEN);</span><br><span class="line">      version[ST_SERVER_VER_LEN - <span class="number">1</span>] = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">      <span class="built_in">do_server_version_split</span>(version, version_split);</span><br><span class="line">      <span class="keyword">if</span> (<span class="built_in">version_product</span>(version_split) &lt; checksum_version_product)</span><br><span class="line">        ret = BINLOG_CHECKSUM_ALG_UNDEF;</span><br><span class="line">      <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="type">size_t</span> checksum_alg_offset =</span><br><span class="line">            len - (BINLOG_CHECKSUM_ALG_DESC_LEN + BINLOG_CHECKSUM_LEN);</span><br><span class="line">        ret =</span><br><span class="line">            <span class="built_in">static_cast</span>&lt;enum_binlog_checksum_alg&gt;(*(buf + checksum_alg_offset));</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="built_in">BAPI_RETURN</span>(ret);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<blockquote>
<p>A format description event is the first event of a binlog for binlog-version 4. It describes how the other events are layed out.</p>
</blockquote>
<p><strong>Row Based Replication Events</strong></p>
<p>In Row Based replication the changed rows are sent to the slave which removes side-effects and makes it more reliable. Now all statements can be sent with RBR though. Most of the time you will see RBR and SBR side by side.</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/table-map-event.html">TABLE_MAP_EVENT</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv0">DELETE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv0">UPDATE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv0">WRITE_ROWS_EVENTv0</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv1">DELETE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv1">UPDATE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv1">WRITE_ROWS_EVENTv1</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#delete-rows-eventv2">DELETE_ROWS_EVENTv2</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#update-rows-eventv2">UPDATE_ROWS_EVENTv2</a></li>
<li><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/rows-event.html#write-rows-eventv2">WRITE_ROWS_EVENTv2</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">00000004  87 77 d4 5e|0f|01 00 00  00|79 00 00 00|7d 00 00  |.w.^.....y...&#125;..|</span><br><span class="line">00000014  00|00 00|04 00|38 2e 30  2e 32 30 00 00 00 00 00  |.....8.0.20.....|</span><br><span class="line">00000024  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|</span><br><span class="line">00000034  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|</span><br><span class="line">00000044  00 00 00 00 00 00 00|87  77 d4 5e|13|00 0d 00 08  |........w.^.....|</span><br><span class="line">00000054  00 00 00 00 04 00 04 00  00 00|61|00 04 1a 08 00  |..........a.....|</span><br><span class="line">00000064  00 00 08 08 08 02 00 00  00 0a 0a 0a 2a 2a 00 12  |............**..|</span><br><span class="line">00000074  34 00 0a 28|01|63 c8 ff  8b                       |4..(.c....w.^#..|</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>Event Header</strong></p>
<blockquote>
<p>timestamp:	87 77 d4 5e  #1590982535</p>
<p>event type:	0f  # <a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/format-description-event.html">FORMAT_DESCRIPTION_EVENT</a></p>
<p>server-id:	01 00 00  00  #1</p>
<p>event-size:	79 00 00 00     #121</p>
<p>log pos:	7d 00 00 00	#125 position of the next event</p>
<p>flag:	00 00	#0</p>
</blockquote>
<p><strong>Event Body</strong> (FORMAT_DESCRIPTION_EVENT)</p>
<blockquote>
<p>binlog-version:	04 00	#4</p>
<p>mysql-server version:	38 2e 30  2e 32 30 00 00 00 00 00 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00	#8.0.20</p>
<p>create timestamp:	87 77 d4 5e	#1590982535</p>
<p>event header length:	13	#19 固定值</p>
<p>event type header lengths：	00 0d 00 08 00 00 00 00 04 00 04 00  00 00	# 长度(15-1)</p>
<p>data length:	61	#97   &#x3D;&#x3D;&gt; #check sum block &#x3D; event-size - event header length - data length &#x3D; 121-19-97 &#x3D; 5</p>
<p>skip:	121(eventSize)-19(header)-2(binlogVersion)-50(serverVersion)-4(time)-1(headerLength)-14(typeHeaderLength)-1(dataLength)-5(checkSumBlock) &#x3D; 25</p>
<p>check sum type:	01 #1 CRC32</p>
</blockquote>
<p>例如：<a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/table-map-event.html">TABLE_MAP_EVENT</a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">post-header:</span><br><span class="line">    if post_header_len == 6 &#123;</span><br><span class="line">  4              table id</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">  6              table id</span><br><span class="line">    &#125;</span><br><span class="line">  2              flags</span><br><span class="line"></span><br><span class="line">payload:</span><br><span class="line">  1              schema name length</span><br><span class="line">  string         schema name</span><br><span class="line">  1              [00]</span><br><span class="line">  1              table name length</span><br><span class="line">  string         table name</span><br><span class="line">  1              [00]</span><br><span class="line">  lenenc-int     column-count</span><br><span class="line">  string.var_len [length=$column-count] column-def</span><br><span class="line">  lenenc-str     column-meta-def</span><br><span class="line">  n              NULL-bitmask, length: (column-count + 8) / 7</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">+=====================================+</span><br><span class="line">|        | fixed part (post-header)   |</span><br><span class="line">| data   +----------------------------+</span><br><span class="line">|        | variable part (payload)    |</span><br><span class="line">+=====================================+</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://dev.mysql.com/doc/internals/en/binlog-file.html">参考</a></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/binlog-protocol/" rel="tag">binlog protocol</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-mysql-server"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/06/02/mysql-server/">mysql-server</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/06/02/mysql-server/" class="article-date">
	  <time datetime="2020-06-02T02:16:25.000Z" itemprop="datePublished">六月 2, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="源码"><a href="#源码" class="headerlink" title="源码"></a>源码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://github.com/mysql/mysql-server.git</span><br></pre></td></tr></table></figure>

<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone git@github.com:mysql/mysql<span class="literal">-server</span>.git</span><br></pre></td></tr></table></figure>



<h2 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">cmake \</span><br><span class="line">-DCMAKE_INSTALL_PREFIX=/tmp/mysql_data/mysql-8.0-rc \</span><br><span class="line">-DMYSQL_DATADIR=/tmp/mysql_data/mysql-8.0-rc/data \</span><br><span class="line">-DSYSCONFDIR=/tmp/mysql_data/mysql-8.0-rc \</span><br><span class="line">-DMYSQL_UNIX_ADDR=/tmp/mysql_data/mysql-8.0-rc/data/mysql.sock \</span><br><span class="line">-DWITH_DEBUG=1  \</span><br><span class="line">-DDOWNLOAD_BOOST=1 \</span><br><span class="line">-DWITH_BOOST=/tmp/boost_1_72</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql-server/" rel="tag">mysql server</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  


  <nav id="page-nav">
    
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><a class="extend next" rel="next" href="/page/2/">下一页</a>
  </nav>

</section>
          <aside id="sidebar">
  
    <div style="margin: 20px 0;">
	<div id="search-form-wrap">

    <form class="search-form">
        <label style="width: 72%;">
            <span class="screen-reader-text">Search for:</span>
            <input type="search" class="search-field" style="height: 36px; width: 100%;" placeholder=" 搜索…" value="" name="s" title="Search for:">
        </label>
        <input type="submit" class="search-form-submit" value="搜索">
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(无标题)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/js/insight.js"></script>


</div>
</div>
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">联系我们</h3>
    <div class="widget widget_athemes_social_icons">

    	<ul class="clearfix widget-social-icons">   
    	
   			<li><a target="_blank" rel="noopener" href="https://github.com/iTimeTraveler" title="Github"><i class="fa fa-github" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Weibo"><i class="fa fa-weibo" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Facebook"><i class="fa fa-facebook" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Google-plus"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Instagram"><i class="fa fa-instagram" aria-hidden="true"></i></a></li> 

   		
   		</ul>


   		<!--
   		<ul class="clearfix widget-social-icons">   		
   		<li class="widget-si-twitter"><a target="_blank" rel="noopener" href="http://twitter.com" title="Twitter"><i class="ico-twitter"></i></a></li> 
		<li class="widget-si-facebook"><a target="_blank" rel="noopener" href="http://facebook.com" title="Facebook"><i class="ico-facebook"></i></a></li>
			<li class="widget-si-gplus"><a target="_blank" rel="noopener" href="http://plus.google.com" title="Google+"><i class="ico-gplus"></i></a></li>
			<li class="widget-si-pinterest"><a target="_blank" rel="noopener" href="http://pinterest.com" title="Pinterest"><i class="ico-pinterest"></i></a></li>
			<li class="widget-si-flickr"><a target="_blank" rel="noopener" href="http://flickr.com" title="Flickr"><i class="ico-flickr"></i></a></li>
			<li class="widget-si-instagram"><a target="_blank" rel="noopener" href="http://instagram.com" title="Instagram"><i class="ico-instagram"></i></a></li>
		</ul> -->

    </div>
  </div>


  
    
  <div class="widget_athemes_tabs">
    <ul id="widget-tab" class="clearfix widget-tab-nav">
      <li class="active"><a>最新文章</a></li>
    </ul>
    <div class="widget">
      <ul>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2022/04/22/debug-mysql-with-clion/">使用Clion调试MySQL Server源码</a></h6>
              <span>四月 22, 2022</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/08/12/dev-prepare/">通用开发环境搭建</a></h6>
              <span>八月 12, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/08/11/zsh/">安装zsh及主题(Mac)</a></h6>
              <span>八月 11, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/06/30/mysql-architecture/">MySQL-architecture</a></h6>
              <span>六月 30, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/01/12/docker-net/">docker_net</a></h6>
              <span>一月 12, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2020/08/26/jdb/">jdb</a></h6>
              <span>八月 26, 2020</span>
            </div>

          </li>
        
      </ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/">Mybatis</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BB%BA%E7%AB%99/">建站</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Endian-%E5%AD%97%E8%8A%82%E5%BA%8F-%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1/" rel="tag">Endian 字节序 网络通信</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/" rel="tag">Git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GitHub-PR/" rel="tag">GitHub PR</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux-Iptables-Netstat-%E7%AB%AF%E5%8F%A3/" rel="tag">Linux Iptables Netstat 端口</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux-diff-comm-grep/" rel="tag">Linux diff comm grep</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyBatis/" rel="tag">MyBatis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MySQL-architecture/" rel="tag">MySQL architecture</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mybatis-MySQL/" rel="tag">Mybatis MySQL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mybatis-Proxy/" rel="tag">Mybatis Proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Net/" rel="tag">Net</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Tcpdump/" rel="tag">Tcpdump</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Tshark/" rel="tag">Tshark</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/binlog-protocol/" rel="tag">binlog protocol</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug-jdb/" rel="tag">debug jdb</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker-mysql/" rel="tag">docker mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker-net/" rel="tag">docker net</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java-maven-docker-mysql-gitlab-github/" rel="tag">java maven docker mysql gitlab github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jvm-classloader/" rel="tag">jvm classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-binlog-xa/" rel="tag">mysql binlog xa</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-server/" rel="tag">mysql server</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-server-debug-clion/" rel="tag">mysql-server debug clion</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx-%E7%81%B0%E5%BA%A6/" rel="tag">nginx 灰度</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zsh-oh-my-zsh/" rel="tag">zsh oh-my-zsh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BB%BA%E7%AB%99/" rel="tag">建站</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/Endian-%E5%AD%97%E8%8A%82%E5%BA%8F-%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1/" style="font-size: 10px;">Endian 字节序 网络通信</a> <a href="/tags/Git/" style="font-size: 20px;">Git</a> <a href="/tags/GitHub-PR/" style="font-size: 10px;">GitHub PR</a> <a href="/tags/Linux/" style="font-size: 20px;">Linux</a> <a href="/tags/Linux-Iptables-Netstat-%E7%AB%AF%E5%8F%A3/" style="font-size: 10px;">Linux Iptables Netstat 端口</a> <a href="/tags/Linux-diff-comm-grep/" style="font-size: 10px;">Linux diff comm grep</a> <a href="/tags/MyBatis/" style="font-size: 10px;">MyBatis</a> <a href="/tags/MySQL-architecture/" style="font-size: 10px;">MySQL architecture</a> <a href="/tags/Mybatis-MySQL/" style="font-size: 10px;">Mybatis MySQL</a> <a href="/tags/Mybatis-Proxy/" style="font-size: 10px;">Mybatis Proxy</a> <a href="/tags/Net/" style="font-size: 20px;">Net</a> <a href="/tags/Tcpdump/" style="font-size: 20px;">Tcpdump</a> <a href="/tags/Tshark/" style="font-size: 10px;">Tshark</a> <a href="/tags/binlog-protocol/" style="font-size: 10px;">binlog protocol</a> <a href="/tags/debug-jdb/" style="font-size: 10px;">debug jdb</a> <a href="/tags/docker-mysql/" style="font-size: 10px;">docker mysql</a> <a href="/tags/docker-net/" style="font-size: 10px;">docker net</a> <a href="/tags/java-maven-docker-mysql-gitlab-github/" style="font-size: 10px;">java maven docker mysql gitlab github</a> <a href="/tags/jvm-classloader/" style="font-size: 10px;">jvm classloader</a> <a href="/tags/mysql-binlog-xa/" style="font-size: 10px;">mysql binlog xa</a> <a href="/tags/mysql-server/" style="font-size: 10px;">mysql server</a> <a href="/tags/mysql-server-debug-clion/" style="font-size: 10px;">mysql-server debug clion</a> <a href="/tags/nginx/" style="font-size: 10px;">nginx</a> <a href="/tags/nginx-%E7%81%B0%E5%BA%A6/" style="font-size: 10px;">nginx 灰度</a> <a href="/tags/zsh-oh-my-zsh/" style="font-size: 10px;">zsh oh-my-zsh</a> <a href="/tags/%E5%BB%BA%E7%AB%99/" style="font-size: 10px;">建站</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>

    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/04/">四月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/08/">八月 2021</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">六月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">一月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">八月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/07/">七月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/06/">六月 2020</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">四月 2020</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">9</span></li></ul>
    </div>
  </div>


  
</aside>
        
      </div>

    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
		<a href="https://beian.miit.gov.cn/" target="_blank">鄂ICP备2023005434号-1</a>  	
	        Copyright &copy; 2023 YouN 科技温度 All Rights Reserved.
        
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hipaper" target="_blank">hipaper</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");

    wrapdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";


    <!-- headerblur min height -->
    
    
</script>

    
<div style="display: none;">
  <script src="https://s11.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
</div>

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>


<script src="/js/bootstrap.js"></script>


<script src="/js/main.js"></script>








  <div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
